﻿using System;
using System.Security.Principal;
using System.Threading;
using System.Windows.Forms;

namespace WinFormAuthentication
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            IPrincipal _principal = Thread.CurrentPrincipal;

            if (_principal.Identity.IsAuthenticated)
            {
                textBox1.Text = "您已经登录，当前用户：" + _principal.Identity.Name;
                textBox1.Text += Environment.NewLine + "当前角色：" + (_principal.IsInRole("管理员") ? "管理员" : "非管理员");
            }
            else
            {
                textBox1.Text = "您还没有登录";
            }
        }
    }
}
